package com.hospital.workstation.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.TextRenderData;
import com.deepoove.poi.data.style.Style;
import com.deepoove.poi.plugin.table.HackLoopTableRenderPolicy;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.hospital.common.core.domain.PageQuery;
import com.hospital.common.core.domain.R;
import com.hospital.common.core.domain.entity.SysDept;
import com.hospital.common.core.domain.entity.SysDictData;
import com.hospital.common.core.domain.model.LoginUser;
import com.hospital.common.core.page.TableDataInfo;
import com.hospital.common.helper.LoginHelper;
import com.hospital.common.utils.StringUtils;
import com.hospital.system.mapper.SysDeptMapper;
import com.hospital.system.mapper.SysDictDataMapper;
import com.hospital.system.mapper.SysUserMapper;
import com.hospital.workstation.constant.DictConstants;
import com.hospital.workstation.domain.*;
import com.hospital.workstation.domain.bo.MedicalRecordBo;
import com.hospital.workstation.domain.bo.MedicationRecordBo;
import com.hospital.workstation.domain.bo.PatientBaseInfoBo;
import com.hospital.workstation.domain.bo.TraditionalDiagnosisBo;
import com.hospital.workstation.domain.vo.*;
import com.hospital.workstation.mapper.*;
import com.hospital.workstation.service.IMedicationRecordService;
import com.hospital.workstation.service.IMedicationSummaryService;
import com.hospital.workstation.service.IPharmaceuticalCareService;
import com.hospital.workstation.utils.CXFClientUtil;
import com.hospital.workstation.utils.PoiTlUtils;
import com.hospital.workstation.webService.domain.Request;
import com.hospital.workstation.webService.domain.Response;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletResponse;
import javax.swing.text.AbstractDocument;
import java.io.*;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 药历首页信息Service业务层处理
 *
 * @author whb
 * @date 2023-02-13
 */
@RequiredArgsConstructor
@Service
public class MedicationRecordServiceImpl implements IMedicationRecordService {

    private final MedicationRecordMapper baseMapper;
    private final SysUserMapper userMapper;
    private final MedicalRecordMapper medicalRecordMapper;
    private final TraditionalDiagnosisMapper traditionalDiagnosisMapper;
    private final PatientBaseInfoMapper patientBaseInfoMapper;
    private final SysDeptMapper deptMapper;
    private final SysDictDataMapper dictDataMapper;
    private final PharmaceuticalCareMapper pharmaceuticalCareMapper;
    private final PharmacyAssessMapper pharmacyAssessMapper;
    private final IPharmaceuticalCareService pharmaceuticalCareService;
    private final MedicationSummaryMapper summaryMapper;
    private final IMedicationSummaryService medicationSummaryService;
    List<Map<String, Object>> medicalRecordList = null; // 现病史用药汇总集合
    List<Map<String, Object>> medicalRecordBeforeList = null; // 既往病史用药汇总集合
    List<Map<String, Object>> medicalRecordInitalList = null; // 初始药物治疗方案集合
    List<Map<String, Object>> initTraditionalList = null; // 初始饮片药物治疗方案集合
    List<Map<String, Object>> inTraditionalDiagnosisList = null; // 中医入院诊断集合
    private final HisAdmittingDiagInfoMapper diagInfoMapper;

    /**
     * 查询药历首页信息
     */
    @Override
    public MedicationRecordVo queryById(Long id) {
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询药历首页信息列表
     */
    @Override
    public TableDataInfo<MedicationRecordVo> queryPageList(MedicationRecordBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<MedicationRecord> lqw = buildQueryWrapper(bo);
        Page<MedicationRecordVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询药历首页信息列表
     */
    @Override
    public List<MedicationRecordVo> queryList(MedicationRecordBo bo) {
        LambdaQueryWrapper<MedicationRecord> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<MedicationRecord> buildQueryWrapper(MedicationRecordBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<MedicationRecord> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getMedicalRecordNo() != null, MedicationRecord::getMedicalRecordNo, bo.getMedicalRecordNo());
        lqw.eq(StringUtils.isNotBlank(bo.getSelfReported()), MedicationRecord::getSelfReported, bo.getSelfReported());
        lqw.eq(StringUtils.isNotBlank(bo.getIsHaveMedicalHistoryNow()), MedicationRecord::getIsHaveMedicalHistoryNow, bo.getIsHaveMedicalHistoryNow());
        lqw.eq(StringUtils.isNotBlank(bo.getMedicalHistoryNow()), MedicationRecord::getMedicalHistoryNow, bo.getMedicalHistoryNow());
        lqw.eq(StringUtils.isNotBlank(bo.getMedicalHistoryBefore()), MedicationRecord::getMedicalHistoryBefore, bo.getMedicalHistoryBefore());
        lqw.eq(StringUtils.isNotBlank(bo.getIsHaveAllergy()), MedicationRecord::getIsHaveAllergy, bo.getIsHaveAllergy());
        lqw.like(StringUtils.isNotBlank(bo.getDoubtPillsOrFoodName()), MedicationRecord::getDoubtPillsOrFoodName, bo.getDoubtPillsOrFoodName());
        lqw.eq(StringUtils.isNotBlank(bo.getAdrClinicFeature()), MedicationRecord::getAdrClinicFeature, bo.getAdrClinicFeature());
        lqw.eq(StringUtils.isNotBlank(bo.getDisposeAndResult()), MedicationRecord::getDisposeAndResult, bo.getDisposeAndResult());
        lqw.eq(StringUtils.isNotBlank(bo.getOtherDisposeAndResult()), MedicationRecord::getOtherDisposeAndResult, bo.getOtherDisposeAndResult());
        lqw.eq(StringUtils.isNotBlank(bo.getFamilyHistory()), MedicationRecord::getFamilyHistory, bo.getFamilyHistory());
        lqw.eq(StringUtils.isNotBlank(bo.getPersonHistory()), MedicationRecord::getPersonHistory, bo.getPersonHistory());
        lqw.eq(StringUtils.isNotBlank(bo.getAdmittingDiagnosisWestern()), MedicationRecord::getAdmittingDiagnosisWestern, bo.getAdmittingDiagnosisWestern());
        lqw.eq(bo.getPharmacyAssessId() != null, MedicationRecord::getPharmacyAssessId, bo.getPharmacyAssessId());
        lqw.eq(StringUtils.isNotBlank(bo.getMedicalGuardianSchedule()), MedicationRecord::getMedicalGuardianSchedule, bo.getMedicalGuardianSchedule());
        lqw.eq(StringUtils.isNotBlank(bo.getIsHaveBadHobby()), MedicationRecord::getIsHaveBadHobby, bo.getIsHaveBadHobby());
        lqw.eq(StringUtils.isNotBlank(bo.getIsWine()), MedicationRecord::getIsWine, bo.getIsWine());
        lqw.eq(bo.getWineYear() != null, MedicationRecord::getWineYear, bo.getWineYear());
        lqw.eq(bo.getWineAmountPerDay() != null, MedicationRecord::getWineAmountPerDay, bo.getWineAmountPerDay());
        lqw.eq(StringUtils.isNotBlank(bo.getIsSmoke()), MedicationRecord::getIsSmoke, bo.getIsSmoke());
        lqw.eq(bo.getSmokeYear() != null, MedicationRecord::getSmokeYear, bo.getSmokeYear());
        lqw.eq(bo.getSmokeAmountPerDay() != null, MedicationRecord::getSmokeAmountPerDay, bo.getSmokeAmountPerDay());
        lqw.eq(StringUtils.isNotBlank(bo.getIsEat()), MedicationRecord::getIsEat, bo.getIsEat());
        lqw.eq(StringUtils.isNotBlank(bo.getEatBadHobby()), MedicationRecord::getEatBadHobby, bo.getEatBadHobby());
        lqw.eq(StringUtils.isNotBlank(bo.getIsOther()), MedicationRecord::getIsOther, bo.getIsOther());
        lqw.eq(StringUtils.isNotBlank(bo.getOtherBadHobby()), MedicationRecord::getOtherBadHobby, bo.getOtherBadHobby());
        return lqw;
    }

    /**
     * 保存药历首页信息
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public R<Void> insertByBo(MedicationRecordBo bo) {
        // 判断登录状态
        LoginUser loginUser = LoginHelper.getLoginUser();
        if (ObjectUtil.isNull(loginUser)) {
            return R.fail("您未登录，请先登录");
        }
        MedicationRecord add = BeanUtil.toBean(bo, MedicationRecord.class);
        validEntityBeforeSave(add);
        // 更新患者基本信息
        PatientBaseInfoBo patientBaseInfoBo = bo.getPatientBaseInfoBo();
        PatientBaseInfo patientBaseInfo = BeanUtil.toBean(patientBaseInfoBo, PatientBaseInfo.class);
        patientBaseInfoMapper.updateById(patientBaseInfo);
        // 保存药历
        if (add.getId() == null) { // 新增
            baseMapper.insert(add);
        } else { // 更新
            baseMapper.updateById(add);
        }
        // 删除已经保存的用药记录
        medicalRecordMapper.delete(new LambdaQueryWrapper<MedicalRecord>()
            .eq(MedicalRecord::getMedicalRecordNo, bo.getMedicalRecordNo())
            .in(MedicalRecord::getMedicalType, 0, 1, 2, 5));
        // 保存现病史用药汇总
        List<MedicalRecordBo> nowMedicalRecordBoList = bo.getNowMedicalRecordList();
        if (ObjectUtil.isNotNull(nowMedicalRecordBoList) && nowMedicalRecordBoList.size() > 0) {
            // 保存现病史用药
            List<MedicalRecord> nowMedicalRecordList = BeanUtil.copyToList(nowMedicalRecordBoList, MedicalRecord.class);
            medicalRecordMapper.insertBatch(nowMedicalRecordList);
        }
        // 保存既往病史用药汇总
        List<MedicalRecordBo> beforeMedicalRecordBoList = bo.getBeforeMedicalRecordList();
        if (ObjectUtil.isNotNull(beforeMedicalRecordBoList) && beforeMedicalRecordBoList.size() > 0) {
            // 保存既往病史用药
            List<MedicalRecord> beforeMedicationRecordList = BeanUtil.copyToList(beforeMedicalRecordBoList, MedicalRecord.class);
            medicalRecordMapper.insertBatch(beforeMedicationRecordList);
        }
        // 删除已经保存的中医的入院诊断记录
        traditionalDiagnosisMapper.delete(new LambdaQueryWrapper<TraditionalDiagnosis>()
            .eq(TraditionalDiagnosis::getMedicalRecordNo, bo.getMedicalRecordNo()));
        // 保存中医入院诊断记录
        List<TraditionalDiagnosisBo> traditionalDiagnosisBoList = bo.getTraditionalDiagnosisList();
        if (ObjectUtil.isNotNull(traditionalDiagnosisBoList) && traditionalDiagnosisBoList.size() > 0) {
            List<TraditionalDiagnosis> traditionalDiagnosisList = BeanUtil.copyToList(traditionalDiagnosisBoList, TraditionalDiagnosis.class);
            traditionalDiagnosisMapper.insertBatch(traditionalDiagnosisList);
        }
        // 保存初始药物诊断方案记录
        List<MedicalRecordBo> initalMedicalRecordBoList = bo.getInitalMedicalRecordList();
        if (ObjectUtil.isNotNull(initalMedicalRecordBoList)) {
            // 保存
            List<MedicalRecord> initalMedicalRecordList = BeanUtil.copyToList(initalMedicalRecordBoList, MedicalRecord.class);
            medicalRecordMapper.insertBatch(initalMedicalRecordList);
        }
        // 保存初始饮片用药
        List<MedicalRecordBo> initTraditionalMedicalList = bo.getInitTraditionalMedicalList();
        if (ObjectUtil.isNotNull(initTraditionalMedicalList)) {
            List<MedicalRecord> initList = BeanUtil.copyToList(initTraditionalMedicalList, MedicalRecord.class);
            medicalRecordMapper.insertBatch(initList);
        }
        // 查询药历小结信息
        MedicationSummary medicationSummary = summaryMapper.selectOne(new LambdaQueryWrapper<MedicationSummary>()
            .eq(MedicationSummary::getMedicalRecordNo, bo.getMedicalRecordNo()));
        if (ObjectUtil.isNull(medicationSummary) && ObjectUtil.isNotNull(patientBaseInfo.getDischargeTime())) {
            // 新增药历小结
            medicationSummary = new MedicationSummary();
            medicationSummary.setMedicalRecordNo(bo.getMedicalRecordNo());
            medicationSummary.setInHospitalDate(patientBaseInfo.getAdmissionTime().toLocalDate());
            medicationSummary.setOutHospitalDate(patientBaseInfo.getDischargeTime().toLocalDate());
            medicationSummary.setSigner(bo.getSigner());
            medicationSummary.setSummaryState("0"); // 0未完成 1已完成
            summaryMapper.insert(medicationSummary);
        }
        return R.ok("保存成功");
    }

    /**
     * 修改药历首页信息
     */
    @Override
    public Boolean updateByBo(MedicationRecordBo bo) {
        MedicationRecord update = BeanUtil.toBean(bo, MedicationRecord.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(MedicationRecord entity) {
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除药历首页信息
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    /**
     * 根据病历号查询药历详情
     *
     * @param medicalRecordNo 病历号
     * @return
     */
    @Override
    public MedicationRecordVo queryByMedicalRecordNo(Integer medicalRecordNo) {
        // 创建药历首页信息视图对象
        MedicationRecordVo medicationRecordVo = new MedicationRecordVo();
        // 查询药历首页信息
        MedicationRecord medicationRecord = baseMapper.selectOne(new LambdaQueryWrapper<MedicationRecord>()
            .eq(MedicationRecord::getMedicalRecordNo, medicalRecordNo));
        if (ObjectUtil.isNotNull(medicationRecord)) {
            medicationRecordVo = BeanUtil.toBean(medicationRecord, MedicationRecordVo.class);
        }
        // 西医入院诊断
        if (StringUtils.isBlank(medicationRecordVo.getAdmittingDiagnosisWestern())) {
            // 从his诊断信息表中查询西医入院诊断
            List<HisAdmittingDiagInfoVo> westDiagList = diagInfoMapper.selectVoList(new LambdaQueryWrapper<HisAdmittingDiagInfo>()
                .eq(HisAdmittingDiagInfo::getMedicalRecordNo, medicalRecordNo)
                .eq(HisAdmittingDiagInfo::getDiagType, DictConstants.DIAG_TYPE_IN)
                .eq(HisAdmittingDiagInfo::getDiagCat, "西医"));
            if (ObjectUtil.isNotNull(westDiagList) && westDiagList.size() > 0) {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < westDiagList.size(); i++) {
                    if (i == westDiagList.size() - 1) {
                        sb.append((i + 1) + "、" + westDiagList.get(i).getDiagDesc());
                        break;
                    }
                    sb.append((i + 1) + "、" + westDiagList.get(i).getDiagDesc() + "；");
                }
                medicationRecordVo.setAdmittingDiagnosisWestern(sb.toString());
            }
        }
        // 查询患者基本信息
        PatientBaseInfoVo patientBaseInfoVo = patientBaseInfoMapper.selectVoOne(new LambdaQueryWrapper<PatientBaseInfo>()
            .eq(PatientBaseInfo::getMedicalRecordNo, medicalRecordNo));
        medicationRecordVo.setPatientBaseInfoVo(patientBaseInfoVo);
        // 查询病历号用药汇总集合
        List<MedicalRecordVo> medicalRecordVoList = medicalRecordMapper.selectVoList(new LambdaQueryWrapper<MedicalRecord>()
            .eq(MedicalRecord::getMedicalRecordNo, medicalRecordNo));
        if (medicalRecordVoList.size() > 0) {
            Map<String, List<MedicalRecordVo>> medicalRecordVoMap = medicalRecordVoList.stream().collect(Collectors.groupingBy(MedicalRecordVo::getMedicalType));
            // 封装现病史用药集合
            medicationRecordVo.setNowMedicalRecordVoList(medicalRecordVoMap.get(DictConstants.MEDICAL_TYPE_NOW));
            // 封装既往病史用药集合
            medicationRecordVo.setBeforeMedicalRecordVoList(medicalRecordVoMap.get(DictConstants.MEDICAL_TYPE_BEFORE));
            // 封装初始药物诊疗方案
            medicationRecordVo.setInitalMedicalRecordVoList(medicalRecordVoMap.get(DictConstants.MEDICAL_TYPE_INITAL));
            // 封装初始饮片用药集合
            medicationRecordVo.setInitTraditionalMedicalList(medicalRecordVoMap.get(DictConstants.MEDICAL_TYPE_INIT_TRADITIONAL));
        }
        // 查询中医的入院诊断列表
        List<TraditionalDiagnosisVo> traditionalDiagnosisVoList = traditionalDiagnosisMapper.selectVoList(new LambdaQueryWrapper<TraditionalDiagnosis>()
            .eq(TraditionalDiagnosis::getMedicalRecordNo, medicalRecordNo)
            .eq(TraditionalDiagnosis::getUseType, DictConstants.USE_TYPE_MEDICATION_INDEX));
        // 如果中医入院诊断列表为空,查询HIS诊断信息表中的中医入院诊断信息
        if (traditionalDiagnosisVoList.size() == 0) {
            List<HisAdmittingDiagInfoVo> westDiagList = diagInfoMapper.selectVoList(new LambdaQueryWrapper<HisAdmittingDiagInfo>()
                .eq(HisAdmittingDiagInfo::getMedicalRecordNo, medicalRecordNo)
                .eq(HisAdmittingDiagInfo::getDiagType, DictConstants.DIAG_TYPE_IN)
                .in(HisAdmittingDiagInfo::getDiagCat, "中医", "证型"));
            String illnessName = null;
            for (HisAdmittingDiagInfoVo hisAdmittingDiagInfoVo :
                westDiagList) {
                if ("中医".equals(hisAdmittingDiagInfoVo.getDiagCat())) {
                    illnessName = hisAdmittingDiagInfoVo.getDiagDesc();
                } else {
                    TraditionalDiagnosisVo traditionalDiagnosisVo = new TraditionalDiagnosisVo();
                    traditionalDiagnosisVo.setMedicalRecordNo(medicalRecordNo);
                    traditionalDiagnosisVo.setIllnessName(illnessName);
                    traditionalDiagnosisVo.setPatternOfSyndrome(hisAdmittingDiagInfoVo.getDiagDesc());
                    traditionalDiagnosisVo.setUseType(DictConstants.USE_TYPE_MEDICATION_INDEX);
                    traditionalDiagnosisVoList.add(traditionalDiagnosisVo);
                }
            }
        }
        medicationRecordVo.setTraditionalDiagnosisVoList(traditionalDiagnosisVoList);

        // 调用HIS病历信息的webservice接口
        // 封装参数
        /*Map<String, Object> params = new HashMap<>();
        params.put("code", "MES0181");
        params.put("xml", new Response().getMES0181Xml(patientBaseInfoVo.getPaadmVisitNo()));
        // 解析返回字符串
        String hipMessageInfo = CXFClientUtil.sendXml("HIPMessageInfo", params);
        // String hipMessageInfo = new Response().getMedicationInfoXml();
        Request request = CXFClientUtil.getRequest(hipMessageInfo);
        Map body = request.getRet_data();
        String chiefComplaints = String.valueOf(body.get("chief_complaints")); // 主诉
        String presentHistory = String.valueOf(body.get("present_history")); // 现病史
        // 既往病史
        String pastHistory = String.valueOf(body.get("past_history"));
        if (StringUtils.isNotBlank(pastHistory)) {
            pastHistory = pastHistory.split("入院前用药清单")[0];
        }
        String familyHistory = String.valueOf(body.get("family_history")); // 家族史
        String personalHistory = String.valueOf(body.get("personal_history")); // 个人史
        // 设置到药历首页信息视图对象中
        if (StringUtils.isBlank(medicationRecordVo.getSelfReported()) && StringUtils.isNotBlank(chiefComplaints)) { // 主诉
            medicationRecordVo.setSelfReported(chiefComplaints);
        }
        if (StringUtils.isBlank(medicationRecordVo.getMedicalHistoryNow()) && StringUtils.isNotBlank(presentHistory)) { // 现病史
            medicationRecordVo.setMedicalHistoryNow(presentHistory);
        }
        if (StringUtils.isBlank(medicationRecordVo.getMedicalHistoryBefore()) && StringUtils.isNotBlank(pastHistory)) { // 既往病史
            medicationRecordVo.setMedicalHistoryBefore(pastHistory);
        }
        if (StringUtils.isBlank(medicationRecordVo.getFamilyHistory()) && StringUtils.isNotBlank(familyHistory)) { // 家族史
            medicationRecordVo.setFamilyHistory(familyHistory);
        }
        if (StringUtils.isBlank(medicationRecordVo.getPersonHistory()) && StringUtils.isNotBlank(personalHistory)) { // 个人史
            medicationRecordVo.setPersonHistory(personalHistory);
        }*/
        //查询药历小结
        List<MedicationSummary> summaryList = summaryMapper.selectList(new LambdaQueryWrapper<MedicationSummary>()
            .eq(MedicationSummary::getMedicalRecordNo, medicalRecordNo));
        if (summaryList.size() == 0) {
            MedicationSummary medicationSummary = new MedicationSummary();
            medicationSummary.setMedicalRecordNo(medicalRecordNo);
            summaryMapper.insert(medicationSummary);
        }
        return medicationRecordVo;
    }

    /**
     * 下载电子药历
     *
     * @param medicalRecordNo 病历号
     */
    @Override
    public void exportWord(HttpServletResponse response, Integer medicalRecordNo) {
        // 获取药历首页下载数据
        Map<String, Object> datas = getIndexMap(medicalRecordNo);
        // 查询患者基本信息
        PatientBaseInfo patientBaseInfo = patientBaseInfoMapper.selectOne(new LambdaQueryWrapper<PatientBaseInfo>().eq(PatientBaseInfo::getMedicalRecordNo, medicalRecordNo));
        try {
            LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
            Configure config = Configure.builder()
                .bind("medicalRecordList", policy)
                .bind("medicalRecordBeforeList", policy)
                .bind("inTraditionalDiagnosisList", policy)
                .bind("medicalRecordInitalList", policy)
                .bind("initTraditionalList", policy)
                .build();
            // 将现病史用药列表保存到渲染的map中
            datas.put("medicalRecordList", medicalRecordList);
            // 将既往用药列表保存到渲染的map中
            datas.put("medicalRecordBeforeList", medicalRecordBeforeList);
            // 将入院中医诊断列表保存到渲染的map中
            datas.put("inTraditionalDiagnosisList", inTraditionalDiagnosisList);
            // 将初始药物治疗方案列表保存到渲染的map中
            datas.put("medicalRecordInitalList", medicalRecordInitalList);
            // 初始饮片保存到渲染的map中
            datas.put("initTraditionalList", initTraditionalList);
            ResourceLoader resourceLoader = new DefaultResourceLoader();
            Resource resource = resourceLoader.getResource("classpath:template/medication_record_index.docx");
            InputStream inputStream = resource.getInputStream();
            XWPFTemplate template = XWPFTemplate.compile(inputStream, config).render(datas);
            PoiTlUtils.createOutPusStream(response, template, medicalRecordNo + "-" + patientBaseInfo.getPatientName() + "-病历首页");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 导出整体电子药历
     *
     * @param response
     * @param medicalRecordNo 病历号
     */
    @Override
    public void overallWord(HttpServletResponse response, Integer medicalRecordNo) {
        // 创建电子药历整体数据集合
        Map<String, Object> datas = new HashMap<>();
        // 电子药历首页数据
        getIndexMap(medicalRecordNo).forEach((k, v) -> {
            datas.put(k, v);
        });
        // 药学监护记录
        Map<String, Object> pharmaceuticalCareMap = pharmaceuticalCareService.getPharmaceuticalCareMap(medicalRecordNo);
        // 出院用药教育
        PharmaceuticalCareVo pharmaceuticalCareVo = pharmaceuticalCareMapper.selectVoOne(new LambdaQueryWrapper<PharmaceuticalCare>().eq(PharmaceuticalCare::getMedicalRecordNo, medicalRecordNo));
        if (ObjectUtil.isNotNull(pharmaceuticalCareVo))
            datas.put("dischargePharmacyEducation", pharmaceuticalCareVo.getDischargePharmacyEducation());
        Map<String, Object> educationMap = pharmaceuticalCareService.getEducationMap(medicalRecordNo);
        // 药历小结
        Map<String, Object> careSummaryMap = medicationSummaryService.getPharmaceuticalCareSummaryMap(medicalRecordNo);
        datas.put("medicationSummaryVo", careSummaryMap.get("medicationSummaryVo"));
        // 查询患者基本信息
        PatientBaseInfo patientBaseInfo = patientBaseInfoMapper.selectOne(new LambdaQueryWrapper<PatientBaseInfo>()
            .eq(PatientBaseInfo::getMedicalRecordNo, medicalRecordNo));

        try {
            LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
            Configure config = Configure.builder()
                .bind("medicalRecordList", policy)
                .bind("medicalRecordBeforeList", policy)
                .bind("inTraditionalDiagnosisList", policy)
                .bind("medicalRecordInitalList", policy)
                .bind("initTraditionalList", policy)
                .bind("careRecordList", policy)
                .bind("traditionalDiagnosisList", policy)
                .bind("medicalRecordList2", policy)
                .bind("summaryTraditionalList", policy)
                .bind("careWestRecordList", policy)
                .bind("careTraditionalRecordList", policy)
                .bind("educWestRecordList", policy)
                .bind("educTraditionalRecordList", policy)
                .build();
            // 现病史用药列表
            datas.put("medicalRecordList", medicalRecordList);
            // 既往用药列表
            datas.put("medicalRecordBeforeList", medicalRecordBeforeList);
            // 入院中医诊断列表
            datas.put("inTraditionalDiagnosisList", inTraditionalDiagnosisList);
            // 初始药物治疗方案列表
            datas.put("medicalRecordInitalList", medicalRecordInitalList);
            // 初始饮片
            datas.put("initTraditionalList", initTraditionalList);
            // 药学监护记录列表
            datas.put("careRecordList", pharmaceuticalCareMap.get("careRecordList"));
            // 出院用药教育西药列表
            datas.put("educWestRecordList", educationMap.get("educWestRecordList"));
            // 出院用药教育中药饮片列表
            datas.put("educTraditionalRecordList", educationMap.get("educTraditionalRecordList"));
            // 中医出院诊断信息列表
            datas.put("traditionalDiagnosisList", careSummaryMap.get("traditionalDiagnosisList"));
            // 住院期间治疗药物汇总信息列表
            datas.put("medicalRecordList2", careSummaryMap.get("medicalRecordList"));
            // 住院期间治疗药物中药饮片汇总列表
            datas.put("summaryTraditionalList", careSummaryMap.get("summaryTraditionalList"));
            ResourceLoader resourceLoader = new DefaultResourceLoader();
            Resource resource = resourceLoader.getResource("classpath:template/overall_medication_record.docx");
            InputStream inputStream = resource.getInputStream();
            XWPFTemplate template = XWPFTemplate.compile(inputStream, config).render(datas);
            PoiTlUtils.createOutPusStream(response, template, medicalRecordNo + "-" + patientBaseInfo.getPatientName() + "-电子病历");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取药历首页下载Map
     *
     * @param medicalRecordNo 药历号
     * @return
     */
    private Map<String, Object> getIndexMap(Integer medicalRecordNo) {
        Map<String, Object> datas = new HashMap<String, Object>();
        // 查询患者基本信息
        PatientBaseInfo patientBaseInfo = patientBaseInfoMapper.selectOne(new LambdaQueryWrapper<PatientBaseInfo>().eq(PatientBaseInfo::getMedicalRecordNo, medicalRecordNo));
        if (patientBaseInfo.getDeptId() != null) { // 病区
            SysDept sysDept = deptMapper.selectById(patientBaseInfo.getDeptId());
            if (ObjectUtil.isNotNull(sysDept)) {
                datas.put("deptName", sysDept.getDeptName());
            }
        }
        // 监护级别
        //查询监护级别字典
        List<SysDictData> guardianLevelDictDataList = dictDataMapper.selectDictDataByType(DictConstants.GUARDIAN_LEVEL_DICT_TYPE);
        Map<String, String> guardLevelMap = guardianLevelDictDataList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        patientBaseInfo.setGuardianLevel(guardLevelMap.get(patientBaseInfo.getGuardianLevel()));
        // 性别
        // 查询性别字典
        List<SysDictData> sexDictList = dictDataMapper.selectDictDataByType(DictConstants.SYS_USER_SEX_DICT_TYPE);
        Map<String, String> sexMap = sexDictList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        patientBaseInfo.setPatientSex(sexMap.get(patientBaseInfo.getPatientSex()));
        // 医保类型
        List<SysDictData> payTypeDictList = dictDataMapper.selectDictDataByType(DictConstants.PAY_WAY_DICT_TYPE);
        Map<String, String> payTypeMap = payTypeDictList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        patientBaseInfo.setPayWay(payTypeMap.get(patientBaseInfo.getPayWay()));
        // 绑定患者基本信息
        datas.put("patientBaseInfo", patientBaseInfo);
        // 查询药历首页信息
        MedicationRecord medicationRecord = baseMapper.selectOne(new LambdaQueryWrapper<MedicationRecord>().eq(MedicationRecord::getMedicalRecordNo, medicalRecordNo));
        // 初始化列表对象
        medicalRecordList = new ArrayList<>();
        medicalRecordBeforeList = new ArrayList<>();
        inTraditionalDiagnosisList = new ArrayList<>();
        medicalRecordInitalList = new ArrayList<>();
        initTraditionalList = new ArrayList<>();
        if (!ObjectUtil.isNull(medicationRecord)) {
            // 查询现病史用药汇总
            List<MedicalRecordVo> medicalRecordVoList = medicalRecordMapper.selectVoList(new LambdaQueryWrapper<MedicalRecord>()
                .eq(MedicalRecord::getMedicalRecordNo, medicalRecordNo));
            Map<String, List<MedicalRecordVo>> medicalRecordMap = medicalRecordVoList.stream().collect(Collectors.groupingBy(MedicalRecordVo::getMedicalType));
            // 查询中医诊断集合
            List<TraditionalDiagnosisVo> traditionalDiagnosisVoList = traditionalDiagnosisMapper.selectVoList(new LambdaQueryWrapper<TraditionalDiagnosis>()
                .eq(TraditionalDiagnosis::getMedicalRecordNo, medicalRecordNo));
            Map<String, List<TraditionalDiagnosisVo>> traditionalDiagnosisVoMap = traditionalDiagnosisVoList.stream().collect(Collectors.groupingBy(TraditionalDiagnosisVo::getUseType));
            // 有无不良嗜好
            String isHaveBadHobby = medicationRecord.getIsHaveBadHobby();
            if (StringUtils.isBlank(isHaveBadHobby) || "0".equals(isHaveBadHobby)) { // 无
                datas.put("isHaveBadHobby2", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                datas.put("isHaveBadHobby1", new TextRenderData("R", new Style("Wingdings 2", 14)));
                datas.put("isWine", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                datas.put("isSmoke", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                datas.put("isEat", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                datas.put("isOther", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                datas.put("eatBadHobby", StringUtils.rightPad("", 60, " "));
                datas.put("otherBadHobby", StringUtils.rightPad("", 60, " "));

            } else { // 有
                datas.put("isHaveBadHobby1", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                datas.put("isHaveBadHobby2", new TextRenderData("R", new Style("Wingdings 2", 14)));
                // 有无饮酒
                String isWine = medicationRecord.getIsWine();
                if (StringUtils.isBlank(isWine) || "0".equals(isWine)) { // 无
                    datas.put("isWine", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                } else { // 有
                    datas.put("isWine", new TextRenderData("R", new Style("Wingdings 2", 14)));
                    // 饮酒年数
                    datas.put("wineYear", medicationRecord.getWineYear());
                    // 每天饮酒两数
                    datas.put("wineAmountPerDay", medicationRecord.getWineAmountPerDay());
                }
                // 有无抽烟
                String isSmoke = medicationRecord.getIsSmoke();
                if (StringUtils.isBlank(isSmoke) || "0".equals(isSmoke)) { // 无
                    datas.put("isSmoke", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                } else { // 有
                    datas.put("isSmoke", new TextRenderData("R", new Style("Wingdings 2", 14)));
                    // 抽烟年数
                    datas.put("smokeYear", medicationRecord.getSmokeYear());
                    // 每天抽烟支数
                    datas.put("smokeAmountPerDay", medicationRecord.getSmokeAmountPerDay());
                }
                // 有无不良的饮食习惯
                String isEat = medicationRecord.getIsEat();
                if (StringUtils.isBlank(isEat) || "0".equals(isEat)) {
                    datas.put("isEat", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                    datas.put("eatBadHobby", StringUtils.rightPad("", 60, " "));
                } else {
                    datas.put("isEat", new TextRenderData("R", new Style("Wingdings 2", 14)));
                    // 不良饮食习惯
                    if (medicationRecord.getEatBadHobby() == null) {
                        datas.put("eatBadHobby", StringUtils.rightPad("", 60, " "));
                    } else if (medicationRecord.getEatBadHobby().length() < 60) {
                        medicationRecord.setEatBadHobby(StringUtils.rightPad(medicationRecord.getEatBadHobby(), 60 - medicationRecord.getEatBadHobby().length(), " "));
                    }
                    datas.put("eatBadHobby", medicationRecord.getEatBadHobby());
                }
                // 有无有其它不良嗜好
                String isOther = medicationRecord.getIsOther();
                if (StringUtils.isBlank(isOther) || "0".equals(isOther)) {
                    datas.put("isOther", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                    datas.put("otherBadHobby", StringUtils.rightPad("", 60, " "));
                } else {
                    datas.put("isOther", new TextRenderData("R", new Style("Wingdings 2", 14)));
                    // 其它不良嗜好
                    if (medicationRecord.getOtherBadHobby() == null) {
                        datas.put("otherBadHobby", StringUtils.rightPad("", 60, " "));
                    } else if (medicationRecord.getOtherBadHobby().length() < 60) {
                        medicationRecord.setOtherBadHobby(StringUtils.rightPad(medicationRecord.getOtherBadHobby(), 60 - medicationRecord.getOtherBadHobby().length(), " "));
                    }
                    datas.put("otherBadHobby", medicationRecord.getOtherBadHobby());
                }
            }
            // 主诉
            datas.put("selfReported", medicationRecord.getSelfReported());
            // 现病史
            datas.put("medicalHistoryNow", medicationRecord.getMedicalHistoryNow());
            List<MedicalRecordVo> medicalTypeNowList = medicalRecordMap.get(DictConstants.MEDICAL_TYPE_NOW);
            if (ObjectUtil.isNotNull(medicalTypeNowList)) {
                medicalTypeNowList.stream().forEach(medicalRecordVo -> {
                    HashMap<String, Object> map = new HashMap<>();
                    // 用药目的
                    map.put("purpose", medicalRecordVo.getPurpose());
                    // 药物名称
                    map.put("pillsName", medicalRecordVo.getPillsName());
                    // 用法用量
                    map.put("amount", medicalRecordVo.getAmount());
                    // 最后用药时间
                    map.put("pillsCycle", medicalRecordVo.getPillsCycle());
                    // 是否继续使用
                    if ("Y".equals(medicalRecordVo.getIsContinue())) {
                        map.put("isContinue", "是");
                    } else if ("N".equals(medicalRecordVo.getIsContinue())) {
                        map.put("isContinue", "否");
                    } else {
                        map.put("isContinue", "");
                    }
                    medicalRecordList.add(map);
                });
                datas.put("notShowNow", false);
                datas.put("showNow", true);
            } else {
                datas.put("notShowNow", true);
                datas.put("showNow", false);
            }
            // 既往病史
            datas.put("medicalHistoryBefore", medicationRecord.getMedicalHistoryBefore());
            // 查询既往病史用药汇总
            List<MedicalRecordVo> beforeList = medicalRecordMap.get(DictConstants.MEDICAL_TYPE_BEFORE);
            if (ObjectUtil.isNotNull(beforeList)) {
                beforeList.stream().forEach(medicalRecordVo -> {
                    HashMap<String, Object> map = new HashMap<>();
                    // 用药目的
                    map.put("purpose", medicalRecordVo.getPurpose());
                    // 药物名称
                    map.put("pillsName", medicalRecordVo.getPillsName());
                    // 用法用量
                    map.put("amount", medicalRecordVo.getAmount());
                    // 最后用药时间
                    map.put("pillsCycle", medicalRecordVo.getPillsCycle());
                    // 是否继续使用
                    if ("Y".equals(medicalRecordVo.getIsContinue())) {
                        map.put("isContinue", "是");
                    } else if ("N".equals(medicalRecordVo.getIsContinue())) {
                        map.put("isContinue", "否");
                    } else {
                        map.put("isContinue", "");
                    }
                    medicalRecordBeforeList.add(map);
                });
                datas.put("notShowBefore", false);
                datas.put("showBefore", true);
            } else {
                datas.put("notShowBefore", true);
                datas.put("showBefore", false);
            }
            // 过敏史及处置史
            String isHaveAllergy = medicationRecord.getIsHaveAllergy();
            if (StringUtils.isBlank(isHaveAllergy) || "0".equals(isHaveAllergy)) { // 无
                datas.put("isHaveAllergy1", new TextRenderData("R", new Style("Wingdings 2", 14)));
                datas.put("isHaveAllergy2", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                medicationRecord.setDoubtPillsOrFoodName(StringUtils.rightPad("", 55, " "));
                medicationRecord.setAdrClinicFeature(StringUtils.rightPad("", 55, " "));
                for (int i = 0; i < 6; i++) {
                    datas.put("disposeAndResult" + i, new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                }
                datas.put("isOtherDisposeAndResult", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                datas.put("otherDisposeAndResult", StringUtils.rightPad("", 49, " "));
            } else { // 有
                datas.put("isHaveAllergy1", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                datas.put("isHaveAllergy2", new TextRenderData("R", new Style("Wingdings 2", 14)));
                if (medicationRecord.getDoubtPillsOrFoodName() == null) {
                    medicationRecord.setDoubtPillsOrFoodName(StringUtils.rightPad("", 55, " "));
                } else if (medicationRecord.getDoubtPillsOrFoodName().length() < 55) {
                    medicationRecord.setDoubtPillsOrFoodName(StringUtils.rightPad(medicationRecord.getDoubtPillsOrFoodName(), 55 - medicationRecord.getDoubtPillsOrFoodName().length(), " "));
                }
                if (medicationRecord.getAdrClinicFeature() == null) {
                    medicationRecord.setAdrClinicFeature(StringUtils.rightPad("", 55, " "));
                } else if (medicationRecord.getAdrClinicFeature().length() < 55) {
                    medicationRecord.setAdrClinicFeature(StringUtils.rightPad(medicationRecord.getAdrClinicFeature(), 55 - medicationRecord.getAdrClinicFeature().length(), " "));
                }
                // 过敏史处理措施及结果
                String disposeAndResult = medicationRecord.getDisposeAndResult();
                for (int i = 0; i < 6; i++) {
                    if (StringUtils.isNotBlank(disposeAndResult) && disposeAndResult.contains(String.valueOf(i))) {
                        datas.put("disposeAndResult" + i, new TextRenderData("R", new Style("Wingdings 2", 14)));
                        continue;
                    }
                    datas.put("disposeAndResult" + i, new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                }
                // 有无有其它过敏
                String isOtherDisposeAndResult = medicationRecord.getIsOtherDisposeAndResult();
                if (StringUtils.isBlank(isOtherDisposeAndResult) || "0".equals(isOtherDisposeAndResult)) { // 无
                    datas.put("isOtherDisposeAndResult", new TextRenderData("\u00A3", new Style("Wingdings 2", 14)));
                    medicationRecord.setOtherDisposeAndResult(StringUtils.rightPad("", 49, " "));
                } else { // 有
                    datas.put("isOtherDisposeAndResult", new TextRenderData("R", new Style("Wingdings 2", 14)));
                    if (medicationRecord.getOtherDisposeAndResult() == null) {
                        medicationRecord.setOtherDisposeAndResult(StringUtils.rightPad("", 49, " "));
                    } else if (medicationRecord.getOtherDisposeAndResult().length() < 49) {
                        medicationRecord.setOtherDisposeAndResult(StringUtils.rightPad(medicationRecord.getOtherDisposeAndResult(), 49 - medicationRecord.getOtherDisposeAndResult().length(), " "));
                    }
                    datas.put("otherDisposeAndResult", medicationRecord.getOtherDisposeAndResult());
                }
            }
            // 查询中医入院诊断表
            List<TraditionalDiagnosisVo> inTradDiagnosisVoList = traditionalDiagnosisVoMap.get(DictConstants.USE_TYPE_MEDICATION_INDEX);
            if (ObjectUtil.isNotNull(inTradDiagnosisVoList)) {
                inTradDiagnosisVoList.stream().forEach(traditionalDiagnosisVo -> {
                    HashMap<String, Object> map = new HashMap<>();
                    map.put("illnessName", traditionalDiagnosisVo.getIllnessName());
                    map.put("patternOfSyndrome", traditionalDiagnosisVo.getPatternOfSyndrome());
                    inTraditionalDiagnosisList.add(map);
                });
            }
            // 查询初始药物治疗方案汇总
            List<MedicalRecordVo> initalMedicalRecordList = medicalRecordMap.get(DictConstants.MEDICAL_TYPE_INITAL);
            if (ObjectUtil.isNotNull(initalMedicalRecordList)) {
                initalMedicalRecordList.stream().forEach(medicalRecordVo -> {
                    HashMap<String, Object> map = new HashMap<>();
                    // 用药目的
                    map.put("purpose", medicalRecordVo.getPurpose());
                    // 药物名称
                    map.put("pillsName", medicalRecordVo.getPillsName());
                    // 单次剂量
                    map.put("amountPer", medicalRecordVo.getAmountPer());
                    // 用法
                    map.put("pillsUsage", medicalRecordVo.getPillsUsage());
                    // 频次
                    map.put("frequency", medicalRecordVo.getFrequency());
                    // 是否继续使用
                    if ("Y".equals(medicalRecordVo.getIsContinue())) {
                        map.put("isContinue", "是");
                    } else if ("N".equals(medicalRecordVo.getIsContinue())) {
                        map.put("isContinue", "否");
                    } else {
                        map.put("isContinue", "");
                    }
                    // 起始日期
                    if (ObjectUtil.isNotNull(medicalRecordVo.getBeginDate()))
                        map.put("beginDate", medicalRecordVo.getBeginDate().toLocalDate());
                    medicalRecordInitalList.add(map);
                });
            }
            // 查询中药饮片初始药物治疗方案汇总
            List<MedicalRecordVo> initTraditionalVoList = medicalRecordMap.get(DictConstants.MEDICAL_TYPE_INIT_TRADITIONAL);
            if (ObjectUtil.isNotNull(initTraditionalVoList)) {
                initTraditionalVoList.stream().forEach(medicalRecordVo -> {
                    HashMap<String, Object> map = new HashMap<>();
                    // 用药目的
                    map.put("purpose", medicalRecordVo.getPurpose());
                    // 药物名称
                    map.put("pillsName", medicalRecordVo.getPillsName());
                    // 用法用量
                    map.put("pillsUsage", medicalRecordVo.getPillsUsage());
                    // 起始日期
                    if (ObjectUtil.isNotNull(medicalRecordVo.getBeginDate()))
                        map.put("beginDate", medicalRecordVo.getBeginDate().toLocalDate());
                    // 结束日期
                    if (ObjectUtil.isNotNull(medicalRecordVo.getEndDate()))
                        map.put("endDate", medicalRecordVo.getEndDate().toLocalDate());
                    initTraditionalList.add(map);
                });
            }
            // 查询入院药学评估
            PharmacyAssessVo pharmacyAssessVo = pharmacyAssessMapper.selectVoOne(new LambdaQueryWrapper<PharmacyAssess>().eq(PharmacyAssess::getMedicalRecordNo, medicalRecordNo));
            if (ObjectUtil.isNotNull(pharmacyAssessVo)) {
                pharmacyAssessVo.setSelfCareAbilityLabel("自理能力：" + pharmacyAssessVo.getSelfCareAbilityLabel());
                pharmacyAssessVo.setExpressionAbilityLabel("患者自述能力评价：" + pharmacyAssessVo.getExpressionAbilityLabel());
                pharmacyAssessVo.setCareLevelLabel("护理级别：" + pharmacyAssessVo.getCareLevelLabel());
                pharmacyAssessVo.setGeneralConditionScoreStr(pharmacyAssessVo.getGeneralConditionScore() + "");
                pharmacyAssessVo.setSmokeWineLabel("烟酒嗜好：" + pharmacyAssessVo.getSmokeWineLabel());
                pharmacyAssessVo.setEatLabel("饮食嗜好：" + pharmacyAssessVo.getEatLabel());
                pharmacyAssessVo.setSportLabel("运动习惯：" + pharmacyAssessVo.getSportLabel());
                pharmacyAssessVo.setLiveStyleScoreStr(pharmacyAssessVo.getLiveStyleScore() + "");
                pharmacyAssessVo.setIsForgetTakePillsLabel(pharmacyAssessVo.getIsForgetTakePillsLabel().trim() + "（" + pharmacyAssessVo.getIsForgetTakePillsSocre() + "分）");
                pharmacyAssessVo.setIsReduceStopPillsLabel(pharmacyAssessVo.getIsReduceStopPillsLabel() + "（" + pharmacyAssessVo.getIsReduceStopPillsScore() + "分）");
                pharmacyAssessVo.setIsForgetCarryPillsLabel(pharmacyAssessVo.getIsForgetCarryPillsLabel() + "（" + pharmacyAssessVo.getIsForgetCarryPillsScore() + "分）");
                pharmacyAssessVo.setIsInsistLabel(pharmacyAssessVo.getIsInsistLabel() + "（" + pharmacyAssessVo.getIsInsistScore() + "分）");
                pharmacyAssessVo.setIsTimeAmountLabel(pharmacyAssessVo.getIsTimeAmountLabel() + "（" + pharmacyAssessVo.getIsTimeAmountScore() + "分）");
                pharmacyAssessVo.setEatPillsHobbyScoreStr(pharmacyAssessVo.getEatPillsHobbyScore() + "");
                pharmacyAssessVo.setIllnessKnowLabel("对所患疾病了解程度：" + pharmacyAssessVo.getIllnessKnowLabel());
                pharmacyAssessVo.setPillsAmountLabel("药物用法用量：" + pharmacyAssessVo.getPillsAmountLabel());
                pharmacyAssessVo.setPillsBadLabel("潜在不良反应：" + pharmacyAssessVo.getPillsBadLabel());
                pharmacyAssessVo.setPillsEffectLabel("药物相互作用：" + pharmacyAssessVo.getPillsEffectLabel());
                pharmacyAssessVo.setGeneralPillsScoreStr(pharmacyAssessVo.getGeneralPillsScore() + "");
                String flag = "不合格";
                if (pharmacyAssessVo.getTotalScore() > 80) {
                    flag = "良好";
                } else if (pharmacyAssessVo.getTotalScore() >= 60 && pharmacyAssessVo.getTotalScore() <= 80) {
                    flag = "合格";
                }
                pharmacyAssessVo.setPharmacyAssessConclusion("总分：" + pharmacyAssessVo.getTotalScore() + "   【" + flag + "】");
                datas.put("pharmacyAssessVo", pharmacyAssessVo);
            }
            // 绑定药历首页
            datas.put("medicationRecord", medicationRecord);
        }
        return datas;
    }
}
